<?php

// +----------------------------------------------------------------------
// | ShuipFCMS 网站前台
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2014 http://www.jsy360.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 神通教育
// +----------------------------------------------------------------------

namespace Content\Controller;

use Common\Controller\Base;


class PhoneController extends Base
{
    protected function _initialize()
    {
		
        parent::_initialize();
    }

    //首页
    public function create()
    {
		C('URL_MODEL',0);
        if (IS_POST) {
            $rules  = array(
                array('phone','require','请输入手机号！'),
                array('phone','/^1[3|4|5|7|8][0-9]\d{4,8}$/','手机号码错误！','0','regex',1),
            );
            $model = M("phone"); // 实例化User对象
            if (!$model->validate($rules)->create()){     // 如果创建失败 表示验证没有通过 输出错误提示信息
                $this->error($model->getError());
            }else{
                $model->ip = get_client_ip();
                if ($model->where(['ip'=>$model->ip])->count() > 5) {
                    $this->error('你的ip超过最多提交次数');
                }

                $model->created_at = date('Y-m-d H:i:s',time());
                $model->add();
                $this->success('提交成功！客服将在12小时内与您取得联系！');
            }
            die();
        }
        $this->display();
    }

}
